/** 
 * Copyright (C), 2010-2012, AIYOU Software Co.,Ltd. ALL RIGHTS RESERVED. 
 * File name:UserLableServiceImp.java
 * Version:1.0
 * Date:2012-1-1
 * Description: 
 * author:whh 
 */
package com.tietiao.service.label;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.tietiao.dao.UserLableMapper;
import com.tietiao.dao.model.UserLable;
import com.tietiao.dao.model.UserLableCriteria;
@Service
public class UserLableServiceImp implements UserLableService {
	@Resource
	private UserLableMapper userLableMapper;

	@Override
	public List<UserLable> getUserLables(int userId, int max) {
		UserLableCriteria userLableCriteria = new UserLableCriteria();
		UserLableCriteria.Criteria criteria = userLableCriteria.createCriteria();
		criteria.andUserIdEqualTo(userId);
		userLableCriteria.setLimit(max);
		userLableCriteria.setStart(0);
		userLableCriteria.setOrderByClause(" create_time desc");
		return userLableMapper.selectByExample(userLableCriteria);
	}

	@Override
	public void attendUserLables(int userId, String lableName) {
		if(!isAttendLable(userId, lableName)){
			UserLable userLable = new UserLable();
			userLable.setLabelName(lableName);
			userLable.setCreateTime(new Date());
			userLable.setUserId(userId);
			userLableMapper.insert(userLable);
		}
	}

	@Override
	public void dontAttendUserLable(int userId, String lableName) {
		userLableMapper.dontAttendUserLable(userId,lableName);
	}

	@Override
	public boolean isAttendLable(int userId, String lableName) {
		UserLableCriteria userLableCriteria = new UserLableCriteria();
		UserLableCriteria.Criteria criteria = userLableCriteria.createCriteria();
		criteria.andUserIdEqualTo(userId);
		criteria.andLabelNameEqualTo(lableName);
		List<UserLable> list = userLableMapper.selectByExample(userLableCriteria);
		if(list==null || list.size()==0){
			return false;
		}else{
			return true;
		}
	}
}
